import {Injectable} from '@angular/core';
import {AjaxService} from "../../public/service/ajax.service";
import {SettingUrl} from "../../public/setting/setting_url";
import {HttpCodesEnum} from "../../public/setting/enums";
import {NzMessageService, NzNotificationService} from "ng-zorro-antd";

@Injectable({
  providedIn: 'root'
})
export class PagesService {

  constructor(private notification: NzNotificationService,
              private ajaxService: AjaxService,
              private message: NzMessageService) {
  }

  /**
   * 登录
   * @param jobnumber
   */
  login(jobnumber) {
    let me = this;
    return new Promise(function (resolve) {
      me.ajaxService.get({
        url: SettingUrl.URL.login.login + jobnumber,
        mask: true,
        auth: false,
        success: (res) => {
          if (res.success && res.code === HttpCodesEnum.Success) {
            me.message.success('身份校验通过');
            resolve(res.data);
          } else if (res.code === '9006') {
            me.notification.error('失败', '员工工号不存在，请重新扫入');
          } else {
            me.notification.error(`失败`, '员工信息校验失败，请联系管理员');
          }
        },
        error: (res) => {
          me.notification.error(`失败`, '服务器连接失败')
        }
      });
    })
  }
}
